﻿<DemoContainer>
    <ApexChart TItem="Order"
               Title="Order Gross Value" OnClick="PointSelected">

        <ApexPointSeries TItem="Order"
                         Items="Orders"
                         Name="Gross Value"
                         SeriesType="SeriesType.Pie"
                         XValue="@(e => e.Country)"
                         YAggregate="@(e => e.Sum(e => e.GrossValue))"
                         OrderByDescending="e=>e.Y" />
    </ApexChart>

    @if (selectedData != null && selectedData.DataPoint != null)
    {
        <Alert BackgroundColor="TablerColor.Primary">
            <h3>You clicked  @selectedData.DataPoint.X  @selectedData.DataPoint.Items.Sum(e => e.NetValue) (@selectedData.DataPoint.Items.Sum(e => e.GrossValue))  </h3>
        </Alert>
    }
    else if (selectedData != null)
    {
        <Alert BackgroundColor="TablerColor.Primary">
            <h3>You clicked the chart but not a data point</h3>
        </Alert>
    }

</DemoContainer>

@code {
    private List<Order> Orders { get; set; } = SampleData.GetOrders();
    private SelectedData<Order> selectedData;
    private void PointSelected(SelectedData<Order> data)
    {
        selectedData = data;
    }
}